package com.yj.yygh.common.exp;


import com.yj.yygh.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R error(Exception e) {

        return R.error().message(e.getMessage());
    }

    @ExceptionHandler(value = ArithmeticException.class)
    @ResponseBody
    public R error(ArithmeticException e) {

        return R.error().message(e.getMessage());
    }

    @ExceptionHandler(value = YyghException.class)
    @ResponseBody
    public R error(YyghException e) {

        return R.error().message(e.getMsg()).code(e.getCode());
    }
 }
